// Copyright (c) [Year] [name of copyright holder]
// [Software Name] is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2. 
// You may obtain a copy of Mulan PSL v2 at:
//          http://license.coscl.org.cn/MulanPSL2 
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
// See the Mulan PSL v2 for more details.

/*!
 * \autor captainpeng
 * \date 2019-12-18
 * \update 2019-12-18
 * \version 1.0
 * \copyright
 */

#ifndef MY_MEMMARK_HPP
#define MY_MEMMARK_HPP

#include"memMan.hpp"

namespace my{

    class memMark{
    public:
        static const int MAX_MARK_SIZE = (UINT16_MAX+1)/64;
    private:  
        uint64_t mMark[MAX_MARK_SIZE];

    public:
        // 关于 0 mark 为计数内存管理专用，所以当其 mark 为 0 的时候
        // 我们应该默认他为计数器内存的，当该 mark 被删除, 则是程序结束的时候
        // 所以别占用该值，将其留给计数器使用
        inline bool getMark(const unsigned short m){
            uint64_t f = 1;
            return ((f<<m%64)&mMark[m/64]) != 0;
        }

        inline void useMark(const unsigned short m){
            uint64_t f = 1;
            mMark[m/64] |= (f<<m%64);
        }

        inline void unMark(const unsigned short m){
            uint64_t f =1;
            mMark[m/64] &= (~(f<<m%64));
        }

        void print(){
            std::cout<<"mark: "<<MAX_MARK_SIZE<<std::endl;
            for(int i = 0;i < MAX_MARK_SIZE; ++i)
                std::cout<<std::hex<<mMark[i]<<" ";
        }
    };
}

#endif
